import java.util.ArrayList;


public class WasteArea extends Object{
	private  ArrayList<WasteDeck> decks = new ArrayList<WasteDeck>();
	private int addCount;
	private Game delegator;
	
	public void setDelegate(Game g){
		delegator=g;
	}
	
	public WasteArea(){
		this.init();
	}
	
	public void init(){
		for(int i=1;i<=6;i++){
			WasteDeck temp = new WasteDeck(i);
			decks.add(temp);
			temp.setDelegate(this);
		}
		addCount=0;
	}
	
	public void addCard(Card cd){
		for(WasteDeck deck:decks){
			if (cd.color==deck.color) {
				Card temp = new Card(cd);
				deck.addCard(temp);
			}
		}
	}
	
	public WasteDeck at(int index){
		return decks.get(index);
	}
	
	public void clear(){
		for(WasteDeck deck:decks){
			deck.clear();
		}
		addCount=0;
	}
	
	public int totalScore(){
		int ret=0;
		for(WasteDeck deck:decks){
			ret+=deck.score();
		}
		return ret;
	}
	
	public boolean collectSix(){
		int count=0;
		for(WasteDeck deck:decks){
			if(deck.size() !=0){
				count ++;
			}
		}
		if(count ==6){
			return true;
		}
		else 
			return false;
	}
	
	public void addList(ArrayList<Card> cds){
		
		if(cds.size()==0){
			delegator.wasteAddFinished();
			System.out.println("WasteArea cards empty");

		}
		else{
			System.out.println("WasteArea cards not empty!!!");

			for(int j=0;j<cds.size();j++){
				Card cd  = cds.get(j);
				for(WasteDeck deck:decks){
					//找到对应牌堆
					if (cd.color==deck.color) {
						Card temp = new Card(cd);
						deck.addCard(temp);
						addCount++;
					}
				}
			}
		}
	
	}
	
	public void wasteDeckAddFinished(){
		addCount--;
		if(addCount==0){
			delegator.wasteAddFinished();
			System.out.println("WasteArea addfinished");
		}
	}
}
